export function scrollFunction(obj, id) {
    obj = document.getElementById(id)

    if (obj.attachEvent) {
        obj.attachEvent('onmousewheel', mouseScroll(obj))
    } else if (obj.addEventListener) {
        obj.addEventListener('DOMMouseScroll', mouseScroll(obj), false)
    }
    obj.onmousewheel = obj.onmousewheel = mouseScroll(obj)
}

export function mouseScroll(obj, callback) {
    return function () {
        let e = window.event || document.all ? window.event : arguments[0] ? arguments[0] : event
        let detail, moveForwardStep, moveBackStep
        let step = 0
        if (e.wheelDelta) { // google 下滑负数： -120
            detail = e.wheelDelta
            moveForwardStep = -1
            moveBackStep = 1
        } else if (e.detail) { // firefox 下滑正数：3
            detail = event.detail
            moveForwardStep = 1
            moveBackStep = -1
        }
        // 鼠标滚轮距离
        step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
        e.preventDefault()
        obj.scrollLeft = obj.scrollLeft + step
    }
}